package com.xbts.screen.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xbts.common.core.domain.R;
import com.xbts.common.core.enums.WorkshopTypeEnum;
import com.xbts.common.core.utils.StringUtils;
import com.xbts.common.core.web.controller.BaseController;
import com.xbts.common.core.web.domain.AjaxResult;
import com.xbts.common.log.annotation.Log;
import com.xbts.common.log.enums.BusinessType;
import com.xbts.common.security.annotation.RequiresPermissions;
import com.xbts.screen.domain.WeWorkshopType;
import com.xbts.screen.domain.WeWorkshopVirtualData;
import com.xbts.screen.service.IWeVirtualDataService;
import com.xbts.screen.service.IWeWorkshopVirtualDataService;
import com.xbts.system.api.RemoteFileService;
import com.xbts.system.api.domain.SysFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 虚拟数据Controller
 */
@Api(tags = "虚拟数据管理")
@RestController
@RequestMapping("/weVirtualData")
public class WeVirtualDataController extends BaseController {

    @Autowired
    private IWeVirtualDataService weVirtualDataService;

    @Autowired
    private IWeWorkshopVirtualDataService weWorkshopVirtualDataService;

    @Log(title = "虚拟数据导入", businessType = BusinessType.IMPORT)
    @RequiresPermissions("system:weVirtualData:import")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) {
        String message = weVirtualDataService.importData(file);
        return success(message);
    }

    /**
     * 模板下载
     */
    @RequiresPermissions("system:weVirtualData:template")
    @GetMapping("/template")
    public AjaxResult template() {
        return success(weVirtualDataService.template());
    }
    /**
     * 根据ID获取车间大屏虚拟数据
     */
    @RequiresPermissions("system:workshop_virtualData:query")
    @GetMapping(value = "/getWorkshopList")
    public AjaxResult workshopErpName() {
        return success(weWorkshopVirtualDataService.list(new LambdaQueryWrapper<WeWorkshopVirtualData>().orderByAsc(WeWorkshopVirtualData::getSort)));
    }
    /**
     * 根据ID获取车间大屏虚拟数据
     */
    @GetMapping(value = "/getWorkshopById")
    public AjaxResult workshopErpName(String id) {
        return success(weWorkshopVirtualDataService.getById(id));
    }
    /**
     * 根据ID修改车间大屏虚拟数据
     */
    @RequiresPermissions("system:workshop_virtualData:edit")
    @PutMapping(value = "/editWorkshopById")
    public AjaxResult workshopErpName(@RequestBody WeWorkshopVirtualData weWorkshopVirtualData) {
        if (weWorkshopVirtualData.getId() == null || weWorkshopVirtualData.getImgUrl() == null) {
            return error("参数非法");
        }
        WeWorkshopVirtualData data = new WeWorkshopVirtualData();
        data.setId(weWorkshopVirtualData.getId());
        data.setImgUrl(weWorkshopVirtualData.getImgUrl());
        data.setRemark(weWorkshopVirtualData.getRemark());
        data.setSort(weWorkshopVirtualData.getSort());
        weWorkshopVirtualDataService.updateById(data);
        return success();
    }

}
